package com.atguigu.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.atguigu.constant.MessageConstant;
import com.atguigu.constant.RedisConstant;
import com.atguigu.entity.Result;
import com.atguigu.pojo.Order;
import com.atguigu.service.OrderMobileService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.JedisPool;

import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderMobileController {

    @Autowired
    JedisPool jedisPool;

    @Reference
    OrderMobileService orderMobileService;

    @RequestMapping("/submit.do")
    public Result submit(@RequestBody Map map) throws Exception {
        String telephone = (String) map.get("telephone");
        String validateCode = (String) map.get("validateCode");
        String jediskey = telephone + RedisConstant.SETMEAL_PIC_RESOURCES;
        String validateCodedb = jedisPool.getResource().get(jediskey);
        if(telephone==null||telephone==""||validateCode==null||validateCode==""){
            return new Result(false,MessageConstant.TELEPHONE_VALIDATECODE_NOTNULL);
        }

        Result result = orderMobileService.submit(map);
        return result;


    }

    @RequestMapping("/findById.do")
    public Result findById(Integer id){
        Map map = orderMobileService.findById(id);
        return new Result(true,MessageConstant.QUERY_ORDER_SUCCESS,map);
    }


}
